home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / cms_logon.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2008-09-03  |  2.2 KB  |  157 lines

  1. #! /bin/sh
  2.  
  3. # Copyright 1995, 1999, 2000 by Paul Mattes.
  4. #  Permission to use, copy, modify, and distribute this software and its
  5. #  documentation for any purpose and without fee is hereby granted,
  6. #  provided that the above copyright notice appear in all copies and that
  7. #  both that copyright notice and this permission notice appear in
  8. #  supporting documentation.
  9.  
  10. # VM login script, which runs as a peer of x3270.
  11. # sh version
  12.  
  13. #set -x
  14. me=`echo $0 | sed 's/.*\///'`
  15.  
  16. # Set up login parameters
  17. tcp_host=${1-ibmsys}
  18. userid=${2-USERID}
  19. password=${3-PASSWORD}
  20.  
  21. # Verbose flag for x3270if
  22. #v="-v"
  23.  
  24. # Define some handly local functions.
  25.  
  26. # x3270 interface function
  27. xi()
  28. {
  29.     X3270OUTPUT=6 X3270INPUT=5 x3270if 5>$ip 6<$op $v "$@"
  30. }
  31.  
  32. # 'xi' function, with space-to-comma translation
  33. xic()
  34. {
  35.         _sep=""
  36.     _cmd="$1("
  37.  
  38.     shift
  39.     while [ $# -gt 0 ]
  40.     do    _cmd="$_cmd$_sep\"$1\""
  41.         _sep=","
  42.         shift
  43.     done
  44.     _cmd="$_cmd)"
  45.     xi "$_cmd"
  46. }
  47.  
  48. # Common x3270 Ascii function
  49. ascii()
  50. {
  51.     xic Ascii $@
  52. }
  53.  
  54. # Common x3270 String function
  55. string()
  56. {
  57.     xic String "$@"
  58. }
  59.  
  60. # x3270 connection status
  61. cstatus()
  62. {
  63.     xi -s 4
  64. }
  65.  
  66. # x3270 rows
  67. rows()
  68. {
  69.     xi -s 7
  70. }
  71.  
  72. # x3270 columns
  73. cols()
  74. {
  75.     xi -s 8
  76. }
  77.  
  78. # Failure.
  79. die()
  80. {
  81.     xic Info "$me error: $@"
  82.     xic CloseScript 1
  83.     exit 1
  84. }
  85.  
  86. # x3270 Snap function
  87. snap()
  88. {
  89.         xic Snap $@
  90. }
  91.  
  92. # Wait for a READ prompt.
  93. waitread()
  94. {
  95.     snap
  96.     while :
  97.     do    r=`snap Rows`
  98.         r=`expr $r - 1`
  99.         c=`snap Cols`
  100.         c=`expr $c - 17`
  101.         s=`snap Ascii $r $c 4`
  102.         [ "$s" = "READ" ] && break
  103.  
  104.         xic Wait Output
  105.         snap
  106.     done
  107. }
  108.  
  109. # Set up pipes for x3270 I/O
  110. ip=/tmp/ip.$$
  111. op=/tmp/op.$$
  112. rm -f $ip $op
  113. trap "rm -f $ip $op" EXIT
  114. trap "exit" INT QUIT HUP TERM
  115. mkfifo $ip $op
  116.  
  117. # Start x3270
  118. x3270 -script -model 2 <$ip >$op &
  119. xp=$!
  120. exec 5>$ip    # hold the pipe open
  121. xi -s 0 >/dev/null || exit 1
  122.  
  123. # Connect to host
  124. xic Connect $tcp_host || die "Connection failed."
  125.  
  126. # Make sure we're connected.
  127. xic Wait InputField
  128. [ "`cstatus`" = N ] && die "Not connected."
  129.  
  130. # Log in.
  131. string "$userid"
  132. xic Tab
  133. string "$password"
  134. xic Enter
  135. waitread
  136. if [ "`ascii 1 11 7`" = "Already" ]
  137. then    die "Can't run -- already logged in."
  138.     exit 1
  139. fi
  140.  
  141. # Boot CMS, if we have to.
  142. r=`rows`
  143. r=`expr $r - 1`
  144. c=`cols`
  145. c=`expr $c - 20`
  146. s=`ascii $r $c 2`
  147. if [ "$s" = "CP" ]
  148. then    xic Clear
  149.     string "i cms"
  150.     xic Enter
  151.     waitread
  152. fi
  153.  
  154. # Done.
  155. xic CloseScript
  156. exit 0
  157.